﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StoryTeller.Repository;
using StoryTeller.Domain;
using System.Linq;
using System.Collections.Generic;

namespace StoryTeller.UnitTest.Repository
{
    [TestClass]
    public class ContributionRepositoryUnitTest
    {
        public ContributionRepository repository { get { return new ContributionRepository(); } }

        public Contribution contribution
        {
            get
            {
                return new Contribution()
                {
                    IsPublic = true,
                    Text = "texto criado ... ",
                    Owner = new UserRepository().Select().First()
                };
            }
        }

        [TestMethod]
        public void Insert()
        {
            repository.Insert(contribution);
        }

        [TestMethod]
        public void Update()
        {
            Contribution ct = repository.Select().Last();
            ct.Text += " - updated" + DateTime.Now.ToShortDateString();

            repository.Update(ct);
        }

        [TestMethod]
        public void Delete()
        {
            Contribution ct = repository.Select().Last();

            repository.Delete(ct.Id);
        }

        [TestMethod]
        public void Select()
        {
            ICollection<Contribution> coll = repository.Select();

            Assert.IsNotNull(coll);
        }

        [TestMethod]
        public void SelectById()
        {
            Contribution ct = repository.Select().Last();

            repository.Select(ct.Id);

            Assert.IsNotNull(ct);
        }
    }
}
